package com.zhu.service;

import com.zhu.mapper.BusinessMapper;
import com.zhu.pojo.Business;
import com.zhu.pojo.CustBus;
import com.zhu.pojo.Customer;
import jakarta.persistence.criteria.CriteriaBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class BusinessService {
    @Autowired
    private BusinessMapper businessMapper;

    public List<Map<String,Object>> SearchNames(){return businessMapper.searchNames();}

    public Integer getbusid(String name){return businessMapper.getbusid(name);}

    public Integer getcustid(String name) {return businessMapper.getcustid(name);}

    public void custlinkbus(CustBus custBus){
        if(businessMapper.checkIfExists(custBus)==0)
            businessMapper.custlinkbus(custBus);
    }

    public List<Integer> getallbusid(Integer id){
        return businessMapper.getallbusid(id);
    }

    public List<Business> findBusinessesByNames(List<Integer> ids){
        return businessMapper.findBusinessesByNames(ids);
    }

    public void update(Business business){ businessMapper.update(business);}

    public void delete(Business business){

        int id = businessMapper.getbusid(business.getBusiness_name());
        businessMapper.deleteCustBus(id);
        businessMapper.delete(business);
    }

    public List<Map<String,Object>> search(Business business){
        return businessMapper.search(business);
    }

    public List<Customer> searchcust(String business_name){
        Integer id = businessMapper.getbusid(business_name);
        List<Integer> ids = businessMapper.searchcustid(id);
        return businessMapper.findCustomerByIds(ids);
    }

    public List<Map<String,Object>> getstaticlist(){
        return businessMapper.getstaticlist();
    }


}
